<?php
/**
 * Created by PhpStorm.
 * User: 王晓亮
 * Date: 2019/3/7 0007
 * Time: 14:46
 */

namespace App\Logics;

class SmsLogic extends BaseLogic
{

    /**
     * @param string $phone
     * @param array $data
     * @param int $type
     * @return array|mixed
     */
    public static function send_msg(string $phone,array $data,int $type){

        if(empty($phone)) return ['status'=>1002,'msg'=>'手机号能为空'];
        if(empty($data) && !is_array($data)) return ['status'=>1002,'msg'=>'内容不能空'];

        $url =  config('sys.sms_send_url');

        $post_data = [
            'phone' =>$phone,
            'data_param'=>base64_encode(json_encode($data)),
            'type'=>$type
            ];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        if(strpos($url,'https')!==false){
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        }
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        $output = curl_exec($ch);
        curl_close($ch);


        if(empty($output)) return ['status'=>1002,'msg'=>'失败'];
        return  json_decode($output,true);

    }





}